package cn.tedu.blog.server.controller.api;


import cn.tedu.blog.server.pojo.dto.UserDetailsDTO;
import cn.tedu.blog.server.pojo.vo.UserDetailsVO;
import cn.tedu.blog.server.pojo.vo.UserLoginVO;
import cn.tedu.blog.server.pojo.vo.UserCenterDetailVO;
import cn.tedu.blog.server.pojo.vo.UserFollowDetailVO;
import cn.tedu.blog.server.service.IUserService;
import cn.tedu.blog.server.utils.JsonResult;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@RestController
@RequestMapping("/api/user")
@Api(tags="前台用户模块")
public class ApiUserController {
    @Autowired
    private IUserService userService;

    @ApiOperation("查询用户数量")
    @GetMapping("/getUserCount")
    public JsonResult count(){
        log.debug("接收到用户数查询请求");
        long  count=userService.userCount();
        return JsonResult.ok(count);
    }

    @ApiOperation("查询用户数量")
    @GetMapping("/selectUser")
    public JsonResult selectUser(){
        log.debug("接收到用户数查询请求");
        UserLoginVO userLoginVO =userService.selectUser();

        return JsonResult.ok(userLoginVO);
    }


    @GetMapping("")
    @ApiOperation("用户中心相关数据")
    @ApiOperationSupport(order = 100)
    public JsonResult getUser(){
        log.info("获取用户中心相关数据");
        UserCenterDetailVO userCenterDetailVO = userService.getUserCenter();
        log.info("返回给客户端数据:{}", userCenterDetailVO);
        return JsonResult.ok(userCenterDetailVO);
    }

    // 查询用户关注的博主列表
    @PostMapping("/follows")
    @ApiOperation("用户关注博主列表")
    @ApiOperationSupport(order = 200)
    public JsonResult getUserByUserId(@RequestParam int pagSize){
        log.info("查询用户关注博主的列表,接收到的参数:{}", pagSize);
        List<UserFollowDetailVO> list = userService.getUserByUserId(pagSize);
        log.info("即将向客户端返回数据:{}", list);
        return JsonResult.ok(list);
    }

    // 查询用户的粉丝列表
    @PostMapping("/fans")
    @ApiOperation("用户粉丝列表")
    @ApiOperationSupport(order = 300)
    public JsonResult getFansByUserId(@RequestParam int pagSize){
        log.info("查询用户关注博主的列表,接收到的参数:{}", pagSize);
        List<UserFollowDetailVO> list = userService.getFansByUserId(pagSize);
        log.info("即将向客户端返回数据:{}", list);
        return JsonResult.ok(list);
    }

    // 查询用户的详细信息
    @GetMapping("/userDeatil")
    @ApiOperation("用户详细信息")
    @ApiOperationSupport(order = 300)
    public JsonResult getUserDetail(){
        log.info("查询用户详细信息");
        UserDetailsVO userDetailsVO = userService.getUserDetailByUserId();
        return JsonResult.ok(userDetailsVO);
    }

    // 修改用户数据
    @PostMapping("/updateUserByUserId")
    @ApiOperation("用户修改数据")
    @ApiOperationSupport(order = 400)
    public JsonResult updateUserByUserId(@RequestBody UserDetailsDTO userDetailsDTO){
        log.info("处理用用户修改数据");
        userService.updateUserByUserId(userDetailsDTO);
        return JsonResult.ok("修改成功!");
    }
}
